import { http } from 'utils'

export async function login(payload) {
  try {
    const res = await http.post('admin/login', payload)
    if (res.code === 1) {
      sessionStorage.token = res.data.token
      return res
    }
    throw res.data
  } catch (err) {
    throw err
  }
}

export async function getAdminList() {
  try {
    const res = await http.get('admin/list')
    if (res.code === 1) {
      return res.data.data
    }
    throw res.info
  } catch (err) {
    throw err
  }
}

export async function addAdmin(payload) {
  try {
    const res = await http.post('admin/save', payload)
    if (res.code === 1) {
      return res
    }
    throw res.info
  } catch (err) {
    throw err
  }
}
